<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        html,body{
            width: 100%;
            height: 100%;
        }
        .box{
            width: 400px;
            height: 300px;
            /* background-color: green; */
            text-align: center;
            margin: auto;
        }
        .content{
            width: 100%;
            display: flex;
            justify-content: space-around;
        }
        .content div{
            width: 100px;
            height: 100px;
            background-color: black;
            margin-top: 10px;
        }
    </style>
</head>
<body>
    <div class="box">
        <button id="btn">点击将div变成红色</button>
        <div class="content">
            <div name="cdiv"></div>
            <div name="cdiv"></div>
            <div name="cdiv"></div>
        </div>
    </div>
</body>
<script>
    var btn = document.getElementById('btn')
    var cdiv = document.getElementsByName('cdiv')
    btn.onclick = function(){
        for(var i=0;i<cdiv.length;i++){
            cdiv[i].style.backgroundColor = "red"
        }
    }
</script>
</html>